Skip to content

feat: add prepare image layout math - #57

Merged
edhor1608 merged 1 commit into
mainfrom
codex/v1-prepare-image-layout
May 14, 2026
Merged

edhor1608 merged 1 commit into
mainfrom
codex/v1-prepare-image-layout

Conversation

@edhor1608

@edhor1608 edhor1608 commented May 14, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Image preparation command with automatic layout detection for landscape vs portrait, scaled borders, and centered cover/contain handling.
    • Smart output path handling that normalizes to .jpg, creates parent directories, rejects directory targets, and avoids filename collisions via incremented suffixes.
  • Documentation

    • Added a specification detailing prepare-image CLI behavior, aspect ratio rules, border rounding, downscaling policy, and output-path contract.
  • Tests

    • Added tests for output-path rules and image layout computation across aspect scenarios.

Review Change Stack

Note

Add image layout math and output path resolution for prepare-image

  • Adds computePrepareImageLayout in src/domain/prepare_image_layout.ts which selects a target canvas (landscape 3:2 up to 2160×1440, portrait 3:4 up to 1440×1920), scales borders, and returns render dimensions, offsets, and an optional centered cover crop.
  • Landscape sources use a cover crop to fill the inner frame; portrait sources use a contain fit (no upscaling, no crop) centered within the canvas.
  • Adds resolvePrepareImageOutputPath in src/domain/output_path.ts which normalizes the output extension to .jpg, creates parent directories, and suffixes with -<index> to avoid overwriting existing files.
  • Throws if the source dimensions are too small to fit within the requested border after canvas selection.

Macroscope summarized b00efbf.

@coderabbitai

coderabbitai Bot commented May 14, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR introduces two domain modules to support the prepare-image feature. The output path module resolves requested image paths to .jpg files, creates parent directories, and handles filename collisions by appending numeric suffixes. The image layout module computes how to frame a source image with a scaled border, selecting between landscape (centered cover-crop) and portrait (scaled-fit) strategies based on source orientation. Comprehensive tests cover both modules, and a specification document outlines the V1 behavior and constraints.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Docstring Coverage ❌ Error Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add prepare image layout math' is clear and directly describes the main addition: the core layout computation logic (computePrepareImageLayout). While the PR also adds output-path resolution, the primary focus is the layout mathematics, making the title appropriately scoped and specific.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/v1-prepare-image-layout
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/v1-prepare-image-layout

Comment @coderabbitai help to get the list of available commands and usage tips.

edhor1608 commented May 14, 2026 •

Copy link
Copy Markdown
Owner Author

coderabbitai[bot]
coderabbitai Bot previously requested changes May 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/domain/output_path.ts`:
- Around line 16-26: The current existence-check-then-return loop (using
existsSync on normalizedPath and candidate) has a TOCTOU race condition; replace
it with an atomic-create approach: inside the loop that constructs candidate
names (using parse, join and parsed.name), attempt to atomically create the file
(e.g., open/create with exclusive flag like fs.open/ openSync with 'wx' or
create a temp file and fs.rename) and only return the candidate after the atomic
create succeeds; on EEXIST (file already created by another process) continue
the loop and ensure any opened file descriptor is closed if used.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b30ff6f4-c3f1-408c-b52d-a95bdff93379

📥 Commits

Reviewing files that changed from the base of the PR and between b7c5e58 and 5c28c6b.

📒 Files selected for processing (5)
  • docs/plans/v1-prepare-image-layout.md
  • src/domain/output_path.ts
  • src/domain/prepare_image_layout.ts
  • tests/output_path.test.ts
  • tests/prepare_image_layout.test.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

**/*.{js,ts,jsx,tsx}: Prioritize using plain JavaScript/TypeScript instead of libraries for fundamental algorithms (e.g., use Array methods instead of lodash)
Use functional programming patterns and immutable data structures in JavaScript/TypeScript code

Files:

  • tests/output_path.test.ts
  • src/domain/output_path.ts
  • src/domain/prepare_image_layout.ts
  • tests/prepare_image_layout.test.ts
tests/**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (AGENTS.md)

Use explicit 30 second timeout for ffmpeg-heavy tests instead of relying on Bun's default 5 second per-test timeout

Files:

  • tests/output_path.test.ts
  • tests/prepare_image_layout.test.ts
src/domain/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Place deterministic policy, analysis, export, report, benchmark, and validation logic in src/domain

Files:

  • src/domain/output_path.ts
  • src/domain/prepare_image_layout.ts
🔇 Additional comments (21)
src/domain/output_path.ts (2)

29-36: LGTM!


1-2: LGTM!

tests/output_path.test.ts (4)

8-14: LGTM!


16-21: LGTM!


23-27: LGTM!


29-35: LGTM!

src/domain/prepare_image_layout.ts (8)

1-52: LGTM!


54-102: LGTM!


104-127: LGTM!


129-152: LGTM!


154-180: LGTM!


182-188: LGTM!


190-194: LGTM!


196-200: LGTM!

docs/plans/v1-prepare-image-layout.md (1)

1-19: LGTM!

tests/prepare_image_layout.test.ts (6)

5-25: LGTM!


27-45: LGTM!


47-64: LGTM!


66-79: LGTM!


81-97: LGTM!


99-114: LGTM!

Comment thread src/domain/output_path.ts
@edhor1608

Copy link
Copy Markdown
Owner Author

@coderabbitai review\n\nAll active review threads have been addressed or replied to and resolved. Please re-review the current stack state.

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

@edhor1608 Sure! I'll re-review the current state of this PR now.

✅ Actions performed

Full review triggered.

@edhor1608
edhor1608 marked this pull request as ready for review May 14, 2026 20:54
@edhor1608
edhor1608 changed the base branch from codex/v1-image-scope-docs to graphite-base/57 May 14, 2026 20:55
@edhor1608
edhor1608 force-pushed the codex/v1-prepare-image-layout branch from 5c28c6b to 1ae3a8c Compare May 14, 2026 20:56
@graphite-app
graphite-app Bot changed the base branch from graphite-base/57 to main May 14, 2026 20:56
@edhor1608
edhor1608 force-pushed the codex/v1-prepare-image-layout branch from 1ae3a8c to b00efbf Compare May 14, 2026 20:56
@edhor1608
edhor1608 dismissed coderabbitai[bot]’s stale review May 14, 2026 21:00

Dismissed after addressed review thread was resolved and fresh CodeRabbit status passed.

edhor1608 commented May 14, 2026 •

Copy link
Copy Markdown
Owner Author

Merge activity

  • May 14, 9:04 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 14, 9:04 PM UTC: @edhor1608 merged this pull request with Graphite.

@edhor1608
edhor1608 merged commit 221120c into main May 14, 2026
3 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b00efbf1b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/output_path.ts
Comment on lines +31 to +33
if (extension === "") {
return `${requestedPath}.jpg`;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject directory-like --out paths before adding .jpg

When requestedPath ends with a path separator and the directory does not exist yet (for example --out exports/), this branch treats it as an extensionless file path and returns exports/.jpg instead of rejecting it as a directory target. That creates a hidden file and violates the CLI contract that --out must be a file path; users who pass a directory path by mistake will get surprising output placement rather than a clear error.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant